home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 874 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: atglab.bls.com!Alun.Champion
  2. From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Q.: How does strtol() handles overflows?
  5. Date: 09 Jan 1996 21:12:02 GMT
  6. Organization: Computer People Inc.
  7. Message-ID: <ALUN.CHAMPION.96Jan9161202@g7240065.bridge.bst.bls.com>
  8. References: <4cuc2h$gup@news.netvision.net.il>
  9. NNTP-Posting-Host: bstfirewall.bst.bls.com
  10. In-reply-to: simchoni@netvision.net.il's message of 9 Jan 1996 18:27:29 GMT
  11.  
  12. In article <4cuc2h$gup@news.netvision.net.il> simchoni@netvision.net.il (Ami Simchoni) writes:
  13.  
  14. : I am trying to make a rubust ascii-to-decimal function which handles 
  15. : input errors and overflows. I want to rely on the standard library as 
  16. : much as possible.
  17.  
  18. : Borland C++ 3.1 and 4.02 doumentation says if an overflow occurs strtol 
  19. : just returns zero - which is not satisfactory, of course.
  20.  
  21. : The BC++3.1 library source which I have, however, sets errno to ERANGE 
  22. : and returns LONG_MIN or LONG_MAX on overflow. This appears both in the 
  23. : code and in the comments.
  24.  
  25. : Does anybody know what the standard says about it?
  26.  
  27. Yeah. It says exactly what the library source does.
  28.  
  29. 7.10.1.5 The strtol function
  30. ...
  31. Returns
  32.   The strtol function returns the converted value, if any. If no conversion 
  33. could be performed, zero is returned. If the correct value is outside the
  34. range of representable values, LONG_MAX or LONG_MIN is returned (according to
  35. the sign of the value), and the value of the macro ERANGE is stored in errno.
  36.  
  37. Et voila
  38. Regards
  39.  
  40.    -A.
  41. -- 
  42. | A.Champion                |
  43.